<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ref 回调函数形式</title>
    <style>
        #result{
            width: 500px;
            height: 400px;
            border:solid 1px #666;
        }
    </style>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            //1. 声明属性
            input = React.createRef();
            result = React.createRef();

            //声明事件回调
            show = () => {
                //3. 获取input元素的值
                let v = this.input.current.value; // current 当前的
                //设置标签的文本
                this.result.current.innerHTML = v;
            }

            render(){
                return <div>
                        {/*回调函数 会在虚拟 DOM 渲染为真实 DOM 之后执行, 并且会将真实 DOM 对象, 作为参数调用该函数*/}
                        {/*2. 添加 ref 标记*/}
                        <input type="text" ref={this.input} /> <button onClick={this.show}>展示</button>
                        <hr />
                        <div id="result" ref={this.result}>
                        
                        </div>
                    </div>
            }
        }

        //渲染
        ReactDOM.render(<App />, document.querySelector("#root"));

    </script>
</body>
</html>